import Config from '@/api/config'

const fileEnUS = require('@/lang/en-US.json') // 英文包
const fileZhCN = require('@/lang/zh-CN.json') // 中文包
const fileZhTW = require('@/lang/zh-TW.json') // 中文繁体包

fileZhCN.updateInfo = Config.updateInfo['zh-CN']
fileZhTW.updateInfo = Config.updateInfo['zh-TW']
fileEnUS.updateInfo = Config.updateInfo['en-US']

const LangEnUS = localStorage['en-US'] && JSON.parse(localStorage['en-US']) || fileEnUS
const LangZhCN = localStorage['zh-CN'] && JSON.parse(localStorage['zh-CN']) || fileZhCN
const LangZhTW = localStorage['zh-TW'] && JSON.parse(localStorage['zh-TW']) || fileZhTW

const langs =  [
    {
        name: '简体中文',
        key: 'zh-CN',
        file: fileZhCN,
        messages: LangZhCN,
        locale: require('vant/lib/locale/lang/zh-CN').default
    },
    {
        name: 'English',
        key: 'en-US',
        file: fileEnUS,
        messages: LangEnUS,
        locale: require('vant/lib/locale/lang/en-US').default
    }
    ,
    {
        name: '繁体中文',
        key: 'zh-TW',
        file: fileZhTW,
        messages: LangZhTW,
        locale: require('vant/lib/locale/lang/zh-TW').default
    }
]

const getLang = function(lang){
    return langs.find(item=>{return item.key==lang})
}

const defaultLang = 'en-US'

export {langs , getLang , defaultLang}
